package com.my.study.filter.config;

import com.my.study.config.InterfaceConfig;
import com.my.study.filter.InterfaceFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {

    @Autowired
    //必须已注入方式创建，否则在LoginFilter中运用到的实体无法注入
    private InterfaceFilter interfaceFilter;

    @Autowired
    private InterfaceConfig interfaceConfig;

    @Bean
    public FilterRegistrationBean registFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(interfaceFilter);
        registration.addUrlPatterns(interfaceConfig.getPatterns());
        registration.setName("InterfaceFilter");
        registration.setOrder(1);
        return registration;
    }

}